package com.sc.nft.entity.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sc.nft.entity.DigitalCollectionProductInfoAuction;
import com.sc.nft.entity.DigitalCollectionProductInfoAuctionCondition;
import com.sc.nft.entity.DigitalCollectionProductInfoAuctionConsumptionCondition;
import com.sc.nft.entity.vo.DigitalCollectionProductInfoAuctionConsumptionConditionVO;
import com.sc.nft.enums.ClassifyType;
import com.sc.nft.enums.CommodityType;
import com.sc.nft.exception.GlobalRunTimeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author 朱梦晨
 * @Description:
 * @date 2024-09-05
 */
@Data
public class ModifyAuctionProductDTO {


    @ApiModelProperty("productId")
    private Long productId;

    @ApiModelProperty("商品类型 ")
    private CommodityType commodityType;


    @ApiModelProperty("活动名称")
    @NotBlank(message = "活动名称不能为空")
    private String firstTitle;

    @ApiModelProperty("商品")
    private DigitalCollectionProductInfoAuctionDTO digitalCollectionProductInfoAuction;

    @ApiModelProperty("参与条件")
    private List<DigitalCollectionProductInfoAuctionConditionDTO> digitalCollectionProductInfoAuctionConditionList;

    @ApiModelProperty("参与藏品")
    private List<Integer> digitalCollectionProductInfoAuctionConsumptionIds;


    @ApiModelProperty("是否为仅熔炼")
    private Boolean isSmeltingOnly = Boolean.FALSE;

    @ApiModelProperty("是否锁仓")
    @NotNull(message = "请设置是否锁仓")
    private Boolean isLockedPosition;

    @ApiModelProperty("锁仓类型 0:省缺 1:时间模式 2:日期形式 时间模式是获取藏品后延后多久,日期形式是统一锁到对应的时间")
    private Integer lockedPositionType;

    @ApiModelProperty("锁仓市场小时")
    private Integer lockedPositionHour;

    @ApiModelProperty("锁仓到期日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lockedPositionTime;

    @ApiModelProperty("是否为平台展示")
    private Boolean platformShow = true;

    @ApiModelProperty("是否为品牌岛展示")
    private Boolean brandShow = false;

    @ApiModelProperty("是否为企业展示")
    private Boolean firmShow = false;

    @ApiModelProperty(value = "规则展示图")
    @NotBlank(message = "规则展示图不能为空")
    private String ruleImg;

    @ApiModelProperty("分类")
    private ClassifyType typeClassify;

    @ApiModelProperty("缩略图")
    @NotBlank(message = "缩略图不能为空")
    private String creationContent;


    @ApiModelProperty("积分价格")
    private BigDecimal integralNum = BigDecimal.valueOf(0.00);

    @ApiModelProperty("作品故事")
    private String productPresentation;

    @ApiModelProperty("权益介绍")
    private String privilegePresentation;

    @ApiModelProperty("开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date beginTime;

    @ApiModelProperty("结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    @ApiModelProperty("系列id")
    private Long catenaId;

    @ApiModelProperty("系列名称")
    private String catenaName;

    /**
     * 详情页图
     */
    @ApiModelProperty("详情页图")
    private String productDetailPicture;
    /**
     * 详情页图类型 1 图片 2:动图 3:3d模型
     */
    @ApiModelProperty("详情页图类型 1 图片 2:动图 3:3d模型")
    private Integer productDetailPictureType;

    @ApiModelProperty("藏品/盲盒Id")
    private Long relationId;



    public Boolean lockedPositionDecide() {
        // 是否为锁仓
        if (!this.isLockedPosition) {
            return true;
        }
        // 是否为锁仓
        if (this.isLockedPosition) {
            // 是锁仓但是是省缺不允许
            if (this.lockedPositionType.equals(0)) {
                throw new GlobalRunTimeException("请设置锁仓类型");
            }
            // 锁时长模式
            if (this.lockedPositionType.equals(1)) {
                // 锁仓市场大小
                if (this.lockedPositionHour > 0 && this.lockedPositionHour <= 99999) {
                    return true;
                }
            }
            // 锁日期模式
            if (this.lockedPositionType.equals(2)) {
                // 锁仓到期日期必须大于当前时间
                if (this.lockedPositionTime.getTime() > System.currentTimeMillis()) {
                    return true;
                }
            }
        }
        return false;
    }
}
